#include <stdio.h>
#include <stdlib.h>
#include "sys/time.h"


#define SIZEX 512
#define SIZEY 512
double A[2][SIZEX][SIZEY];
#define alpha 0.0876
#define beta 0.0765
#define Do2d5pkernel(itr,i,j){\
A[itr%2][i][j]=alpha*A[(itr+1)%2][i][j]+beta*(A[(itr+1)%2][i-1][j]+A[(itr+1)%2][i+1][j]+A[(itr+1)%2][i][j-1]+A[(itr+1)%2][i][j+1]);}


int main()
{
  int i,j,itr;
  struct timeval start;
  struct timeval end;
  double total_time;    
  int iter=256;

  for(i=0;i<SIZEX;i++)
   for(j=0;j<SIZEY;j++)
     A[1][i][j]=(double)(i*2.5+j*3.3)/3.0;

  gettimeofday(&start,NULL);
  for(itr=0;itr<iter;++itr)
  {
      for(i=1;i<SIZEX-1;i++)
        for(j=1;j<SIZEY-1;j++)
          A[itr%2][i][j]=alpha*A[(itr+1)%2][i][j]+
                         beta*(A[(itr+1)%2][i-1][j]+A[(itr+1)%2][i+1][j]+
                         A[(itr+1)%2][i][j-1]+A[(itr+1)%2][i][j+1]); 
  }
  gettimeofday(&end,NULL);
  total_time = 0.0;
  total_time+=(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000000.0;
  printf("time:%lf\n",total_time);
  return 0;
}
   


